package com.chinasoft.maysham.manager.repo.project;

import com.chinasoft.maysham.manager.model.ProjectUser;
import com.chinasoft.maysham.manager.repo.BaseRepo;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

@Repository
public class ProjectUserRepo extends BaseRepo {

    public void deleteUser(String userId) {
        template.updateMulti(Query.query(Criteria.where("userId").is(userId).and("deleted").is(false)), Update.update("deleted", true), ProjectUser.class);
    }

    public ProjectUser findByUserIdAndProjectId(String userId, String projectId) {
        return template.findOne(Query.query(Criteria.where("userId").is(userId).and("projectId").is(projectId).and("deleted").is(false)), ProjectUser.class);
    }
}
